package com.qf.tenant.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.dto.PageDto;
import com.qf.tenant.entity.Tenant;
import com.qf.tenant.mapper.TenantMapper;
import com.qf.tenant.service.TenantService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.vo.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 租户表 服务实现类
 * </p>
 *
 * @author 程序员(李楚枫)
 * @since 2023-10-30
 */
@Service
public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> implements TenantService {

    @Override
    public PageResult<Tenant> pageInfo(PageDto<Tenant> pageDto) {
        //分页信息
        IPage<Tenant> page = new Page<>(pageDto.getNow(),pageDto.getSize());

        //条件查询
        QueryWrapper<Tenant> qw = new QueryWrapper<>();
        if (!StringUtils.isEmpty(pageDto.getWhere().getName())) {
            qw.lambda().like(Tenant::getName, pageDto.getWhere().getName());
        }
        if (!StringUtils.isEmpty(pageDto.getWhere().getAccessKey())){
            qw.lambda().like(Tenant::getAccessKey, pageDto.getWhere().getAccessKey());
        }

        IPage<Tenant> pageInfo = this.baseMapper.selectPage(page, qw);

        //封装分页结果
        PageResult<Tenant> pageResult = new PageResult<>(pageInfo.getTotal(),pageInfo.getPages(),pageInfo.getRecords());

        return pageResult;
    }
}
